package com.demo.actionbartabnavdemo;

import android.app.ActionBar;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;

public class MainActivity extends Activity {

    ActionBar.TabListener listener = new ActionBar.TabListener() {
        @Override
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
            TelephoneFragment frag = new TelephoneFragment();
            Bundle b = new Bundle();
            b.putInt("TAB_ID", tab.getPosition() + 1);
            frag.setArguments(b);
            FragmentTransaction fragtrans = getFragmentManager().beginTransaction();
            fragtrans.replace(R.id.container, frag);
            fragtrans.commit();
        }

        @Override
        public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {

        }

        @Override
        public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {

        }
    };
    private ActionBar actionBar = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        actionBar = getActionBar(); // getSupportActionBar()
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionBar.addTab(actionBar.newTab().setText("已接电话").setTabListener(listener));
        actionBar.addTab(actionBar.newTab().setText("未接电话").setTabListener(listener));
        actionBar.addTab(actionBar.newTab().setText("已拔电话").setTabListener(listener));
    }
}
